package com.example.leepong.Game.Entities;

import com.example.leepong.Game.CoordinatesMover;
import com.example.leepong.Game.Shapes.Rectangle;

/**
 * Created by Ichigo on 27/02/14.
 */
public class Ball {
    public Rectangle Rect;

    // -180 +180
    public int Angle;

    // px per calculated frame
    public float MoveStep;
    public float DefaultMoveStep;
    public float NormalizeSpeedRatio;

    public Ball() {
        this.Rect = new Rectangle();
    }

    public void Update() {
        CoordinatesMover.Move(this.Rect.Coord, this.Angle, this.MoveStep);
        NormalizeAngle();
        NormalizeSpeed();
    }

    public void NormalizeSpeed() {
        float diff = MoveStep - DefaultMoveStep;
        this.MoveStep = MoveStep - (diff * NormalizeSpeedRatio);
    }

    public void ReflectAngleY() {
        this.Angle = 180 - this.Angle;
    }

    public void ReverseAngle() {
        this.Angle = this.Angle - 180;
    }

    public void ReflectAngleX() {
        this.Angle = -this.Angle;
    }

    public void NormalizeAngle() {
        Angle = Angle % 360;
        if (Angle > 180) {
            Angle = Angle - 360;
        }
        if (Angle < -180) {
            Angle = Angle + 360;
        }
    }

    public boolean IsToTop() {
        return Angle < 0 && Angle > -180;
    }

    public boolean IsToBottom() {
        return !IsToTop();
    }

    public boolean IsToRight() {
        return Angle < 90 && Angle > -90;
    }

    public boolean IsToLeft() {
        return !IsToRight();
    }

}